#include<bits/stdc++.h>
using namespace std;
int main(){
	stack<int> a, b;
	int len1, len2;
	cin>>len1>>len2;
	
	// 永远保持b长度小于a
	if(len1 < len2)
		swap(len1, len2);
	
	char ch;
	int x;
	while(cin>>ch){
		if(ch == 'T')
			break;
		if(ch == 'A'){
			cin>>x;
			// 小栈满且大栈非空，无法存入
			if(b.size() == len2 && !a.empty())
				cout<<"ERROR:Full"<<endl;
			// 小栈满且大栈空，小栈逆入大栈，存入小栈
			else if(b.size() == len2 && a.empty()){
				while(!b.empty()){
					a.push(b.top());
					b.pop();
				}
				b.push(x);
			}
			// 小栈未满，直接存入小栈
			else if(b.size() != len2)
				b.push(x);
		}
		// D
		else{
			if(!a.empty()){
				cout<<a.top()<<endl;
				a.pop();
			}
			else if(!b.empty()){
				while(!b.empty()){
					a.push(b.top());
					b.pop();
				}
				cout<<a.top()<<endl;
				a.pop();
			}
			else
				cout<<"ERROR:Empty"<<endl;
		}
	}
	return 0;
}
